package com.ruoyi.hospital.doctor.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.hospital.doctor.domain.TDoctor;
import com.ruoyi.hospital.doctor.service.ITDoctorService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 医生管理Controller
 *
 * @author Shawn
 * @date 2024-02-20
 */
@Controller
@RequestMapping("/hospital/doctor")
public class TDoctorController extends BaseController {
    private String prefix = "hospital/doctor";

    @Autowired
    private ITDoctorService tDoctorService;

    @RequiresPermissions("hospital:doctor:view")
    @GetMapping()
    public String doctor() {
        return prefix + "/doctor";
    }

    /**
     * 查询医生管理列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TDoctor tDoctor) {
        startPage();
        List<TDoctor> list = tDoctorService.selectTDoctorList(tDoctor);
        return getDataTable(list);
    }

    /**
     * 导出医生管理列表
     */
    @RequiresPermissions("hospital:doctor:export")
    @Log(title = "医生管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TDoctor tDoctor) {
        List<TDoctor> list = tDoctorService.selectTDoctorList(tDoctor);
        ExcelUtil<TDoctor> util = new ExcelUtil<TDoctor>(TDoctor.class);
        return util.exportExcel(list, "医生管理数据");
    }

    /**
     * 新增医生管理
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存医生管理
     */
    @RequiresPermissions("hospital:doctor:add")
    @Log(title = "医生管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TDoctor tDoctor) {
        return toAjax(tDoctorService.insertTDoctor(tDoctor));
    }

    /**
     * 修改医生管理
     */
    @RequiresPermissions("hospital:doctor:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        TDoctor tDoctor = tDoctorService.selectTDoctorById(id);
        mmap.put("tDoctor", tDoctor);
        return prefix + "/edit";
    }

    /**
     * 修改保存医生管理
     */
    @RequiresPermissions("hospital:doctor:edit")
    @Log(title = "医生管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TDoctor tDoctor) {
        return toAjax(tDoctorService.updateTDoctor(tDoctor));
    }

    /**
     * 删除医生管理
     */
    @RequiresPermissions("hospital:doctor:remove")
    @Log(title = "医生管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(tDoctorService.deleteTDoctorByIds(ids));
    }

    @RequestMapping("/selectDoctor")
    public String selectDoctor(String type,String registrationType,ModelMap modelMap) {
        modelMap.addAttribute("type",type);
        modelMap.addAttribute("registrationType",registrationType);
        return prefix + "/selectDoctor";
    }
}
